package com.wshl.aijiuunion;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.blankj.utilcode.util.LogUtils;
import com.wshl.aijiuunion.view.bean.EventBeans;
import com.wshl.aijiuunion.utils.BarUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


/**
 * Created by Administrator on 2018/8/6.
 */

public abstract class BaseActivity extends AppCompatActivity {



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏显示

        //设置通知栏颜色
        //StatusColor.setStatusColor(this, R.color.translation);
        //setStatusBar();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(getLayoutResource());
        BarUtils.setWhiteStatusBarForActivity(this);
        // StatusBarUtil.setTranslucent(this, 100);
        //eventbus注册
        EventBus.getDefault().register(this);

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void closectivity(EventBeans eventString) {
        //当接收到关闭页面的广播后
        if (eventString.getCode().equals(GlobConstant.FINISHACLLACTIVITY)) {
            LogUtils.i("关闭所有页面");
            this.finish();
        }
    }

    protected abstract
    @LayoutRes
    int getLayoutResource();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //eventbus反注册
        EventBus.getDefault().unregister(this);
    }


    //下边这两个方法,解决字体跟随系统字体变化的问题
    //如果使用了dp作为字体大小的单位,则不需要这两个方法
 /*   @Override
    public void onConfigurationChanged(Configuration newConfig) {
        //非默认值
        if (newConfig.fontScale != 1) {
            getResources();
        }
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        //还原字体大小
        Resources res = super.getResources();
        //非默认值
        if (res.getConfiguration().fontScale != 1) {
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();
            //设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
    */


}


